<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .wrap {
            width: 400px;
            height: 400px;
            margin: 50px auto;
        }

        .wrap ul li {
            width: 100%;
            height: 300px;
            border: 1px dashed red;
            padding: 20px;
            box-sizing: border-box;
            margin-bottom: 20px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul>
            <!-- <li>
                <input type="checkbox" name="" id="">
                <p>商品名称：</p>
                <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg"
                    alt="">
                <p>商品价格</p>
                <p>商品数量</p>
                <p>商品规格</p>
                <p class="cked">是否选中</p>
            </li> -->
        </ul>
        <span>总数量：</span>
    </div>
    <script>
        let products = [
            {
                goods_name: '小米10-1',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '500',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 10,
                goods_is_checked: true
            },
            {
                goods_name: '小米10-2',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '510',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 50,
                goods_is_checked: false
            }
        ]
        // 数据渲染
        let ul = document.querySelector('ul');
        let uli = '';
        for (let i = 0; i < products.length; i++) {
            uli += `<li>
                        <input type="checkbox" name="" id="" class="ckd" ${products[i].goods_is_checked ? 'checked' : ''}>
                        <p>商品名称：${products[i].goods_name}</p>
                        <img src="https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg" alt="">
                        <p>商品价格：${products[i].goods_price}</p>
                        <p>商品数量：${products[i].goods_num}</p>
                        <p>商品规格：${products[i].goods_attr}</p>
                        <p>是否选中：${products[i].goods_is_checked ? '选中吧' : '不选中'}</p>
                    </li>`;
            ul.innerHTML = uli;
            let ckd = ul.querySelectorAll('.ckd');
            let span = document.querySelector('span');
            console.log(ckd, span);
            // 判断默认选中的给span添加具体数量
            if (products[i].goods_is_checked) {
                span.innerHTML = `总数量：${products[i].goods_num}`;
            };
        };
    </script>
</body>

</html>